package com.alibaba.citrus.cr.platform.enhance.facade.service;

import com.alibaba.citrus.cr.common.lock.RedisLock;
import com.alibaba.cz.base.tool.log.Log;

import com.epoch.app.crplatformenhance.commoncheck.dto.TestLockRequest;
import com.epoch.app.crplatformenhance.commoncheck.service.CommonCheckService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
 * @author luyi
 * @date 2021/11/30 12:00 上午
 */
@Primary
@Component
public class CommonCheckServiceImpl implements CommonCheckService {

    private static Log log = Log.getLogger(CommonCheckServiceImpl.class);

    @Override
    public Object testLock(TestLockRequest testLockRequest) {
        try (RedisLock lock = new RedisLock(testLockRequest.getCacheCode(),testLockRequest.getKey())){
            boolean locked = lock.lock();
            if (locked){
                log.info("ThreadId:"+Thread.currentThread().getId()+"获取锁成功");
                log.info("ThreadId:"+Thread.currentThread().getId()+"处理任务信息");
            }else {
                log.info("ThreadId:"+Thread.currentThread().getId()+"获取锁失败");
            }
        }catch (Exception e){
            log.error("异常：",e);
        }


        return null;
    }
}
